<!DOCTYPE html>
<html lang="en">

<head>
    <script src="/public/js/jquery-3.3.1.min.js"></script>
    <meta http-equiv="Content-Type" content="register/html; charset=gb2312">
    <title>发表文章
    </title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
            width: 100%;
            overflow: hidden;
            margin: 0;
            padding: 0;
            background: url(/public/img/loginregistBack.png) no-repeat 0px 0px;
            background-repeat: no-repeat;
            background-size: 100% 100%;
            -moz-background-size: 100% 100%;
        }

        body {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
        }

        #loginDiv {
            width: 37%;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 650px;
            background-color: rgba(75, 81, 95, 0.3);
            box-shadow: 7px 7px 17px rgba(52, 56, 66, 0.5);
            border-radius: 5px;
        }

        #name_trip {
            margin-left: 50px;
            color: red;
        }

        p,
        .sexDiv {
            margin-top: 10px;
            /*margin-left: 20px;*/
            color: azure;

        }

        .sexDiv>input,
        .hobby>input {
            width: 30px;
            height: 17px;
        }

        #topics,
        select {
            margin-left: 15px;
            border-radius: 5px;
            border-style: hidden;
            height: 30px;
            width: 140px;
            background-color: rgba(216, 191, 216, 0.5);
            outline: none;
            color: #f0edf3;
            padding-left: 10px;
        }
        .isbutton,
        select {
            margin-left: 15px;
            border-radius: 5px;
            border-style: hidden;
            height: 30px;
            width: 140px;
            background-color: rgba(100, 149, 237, .7);
            outline: none;
            color: #f0edf3;
            padding-left: 10px;
        }

        .button {
            border-color: cornsilk;
            background-color: rgba(100, 149, 237, .7);
            color: aliceblue;
            border-style: hidden;
            border-radius: 5px;
            width: 100px;
            height: 31px;
            font-size: 16px;
        }

        .introduce {
            margin-left: 110px;
        }

        .introduce>textarea {
            background-color: rgba(216, 191, 216, 0.5);
            border-style: hidden;
            outline: none;
            border-radius: 5px;
        }

        h1 {
            text-align: center;
            margin-bottom: 20px;
            margin-top: 20px;
            color: #f0edf3;
        }

        b {
            margin-left: 50px;
            color: #FFEB3B;
            font-size: 10px;
            font-weight: initial;
        }
        #ps{
            display: contents;
        }

    </style>
</head>

<body>
<div id="loginDiv">
    <form action="" >
        <h1>发表文章</h1>
        <p style="    margin-left: 34px;">
            主题:
            <input style="margin-left: 32px;width: 260px;height: 30px;" id="topics" name="topics" type="text">
            <label id="name_trip"></label>
        </p>
        <p > 文章内容:</p>
        <div class="introduce">
            <textarea name="introduce" cols="30" id="introduceText" required rows="10" style="width: 936px;height: 300px"></textarea>
            <label id="introduce_trip"></label>
        </div>
        <p id="ps" > 标签:</p>
        <input type="checkbox" style="margin-left: 68px;
    margin-top: 18px;margin-right: 5px;" name="vehicle" checked="checked" value="php">php
        <input style=" margin-right: 5px;" type="checkbox" name="vehicle" value="java">java
        <input style="margin-right: 5px;" type="checkbox" name="vehicle" value="C">C
        <input style="margin-right: 5px;" type="checkbox" name="vehicle" value="C++">C++
        <input style="margin-right: 5px;" type="checkbox" name="vehicle" value="技术">技术
        <input style="margin-right: 5px;" type="checkbox" name="vehicle" value="生活">生活
        <p style="text-align: center;">
            <input type="button" class="isbutton" value="提交">
            <input type="reset" class="button" value="重置">
        </p>
    </form>
</div>

</body>
<script type="text/javascript">
    $('.isbutton').on('click',function() {
        $theme = $("input[name='topics']").val();
        $vehicles="";
        $.each($('input:checkbox:checked'),function () {
                $vehicles=$vehicles+($(this).val())+"&";
        });
        alert($vehicles);
        $intro = $("textarea[name = 'introduce']").val();
        if ($theme==""){
            alert("请输入主题");
        }else if ($intro==""){
            alert("内容不能为空！")
        }else {
            $.ajax({
                url:"/index.php?c=Publish&a=publishSure",
                type:"POST",
                data:{
                    topics:$("input[name='topics']").val(),
                    introduce:$intro,
                    vehicle:$vehicles
                },
                dataType:"json",
                success:function (data){
                    console.log(data)
                    if (data.flag){
                        alert(data.msg);
                        location.href="/index.php";
                    }else {
                        alert(data.msg);
                    }
                },
                error:function (){
                    alert("请求失败")
                }
            });
        }
    });


</script>
</html>

